package com.anlu.concurrent.ch3.answer;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * Copyright: 天津联想协同科技有限公司
 * <p>
 *
 * @author anlu
 * @date 2021/9/8 10:47
 */
public class HalfAtomicInt {
    private AtomicInteger atomicInteger = new AtomicInteger(0);

    public void increment(){
        for (;;){
            int i = atomicInteger.get();
            boolean suc = atomicInteger.compareAndSet(i,++i);
            if(suc){
                break;
            }
        }
    }

    public  int getCount(){
        return atomicInteger.get();
    }
}
